import Packet from "../net/Packet"

// 创建角色
export default class AccountRoleCreate {
	/**
	 * @param sid 服务器ID
	 * @param sex 性别
	 * @param name 名字
	 */
	public constructor(public sid: number, public sex: number, public name: string) { }

	public encode(): Packet {
		const packet = this._encode()
		packet.Encode(2070)
		return packet
	}

	public encodeMsg(): ByteBuffer {
		return this._encode().GetBuffer()
	}

	public static decode(packet: Packet): AccountRoleCreate {
		const sid = packet.ReadUshort()
		const sex = packet.ReadByte()
		const name = packet.ReadString()
		return new AccountRoleCreate(sid, sex, name)
	}

	private _encode(): Packet {
		const packet = new Packet()
		packet.WriteUshort(this.sid)
		packet.WriteByte(this.sex)
		packet.WriteString(this.name)
		return packet
	}
}
